/*
 * Copyright 2009 Andreas Borglin andreas.borglin@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package borge.mobile.lib.pimp;


/**
 * This class can be used to find out which operations listed in ImageConstants
 * are supported on this phone. Each supported operation is connected to
 * a ImageOperation instance that will provide information about that
 * operation.
 * @author Andreas Borglin
 */
public class ImageSupport implements ImageConstants{
    
    
    private ImageOperation[] supportList;

    protected ImageSupport(ImageOperation[] sl) {
        supportList = sl;
    }
    
    /**
     * Find out if a certain operation is supported by the framework/phone.
     * @param operation
     * @return True if supported, false if not.
     */
    public boolean isSupported(int operation) throws IllegalArgumentException{
        
        if(supportList[operation] == null || operation < 0 || operation >= OPERATIONS)
            throw new IllegalArgumentException("Value out of range");
        
        return supportList[operation].isSupported();
    }
    
    /**
     * Get an ImageOperation instance for a certain operation.
     * @param operation The operation integer value from ImageConstants
     * @return An instance of the ImageOperation class
     * @throws java.lang.IllegalArgumentException On out of range values and operations that are not supported.
     */
    public ImageOperation getImageOperation(int operation) throws IllegalArgumentException {
        
        if(operation < 0 || operation >= OPERATIONS)
            throw new IllegalArgumentException("Value out of range");
        
        if(supportList[operation] == null || !supportList[operation].isSupported())
            throw new IllegalArgumentException("Operation not supported");
        
        return supportList[operation];
    }

}
